<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wrr123.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="HTML中文问题可以在浏览器上设置编码方式为GB2312，或者在html的最前面加上编码 123&lt;html&gt;    &lt;meta http-equiv&#x3D;&quot;Content-Type&quot; content&#x3D;&quot;text&#x2F;html;charset&#x3D;GB2312&quot;&#x2F;&gt;&lt;&#x2F;html&gt; 元素 完整的HTML 一个完整的html文件应该至少包含html元素，body元素，以及里面的内">
<meta property="og:type" content="article">
<meta property="og:title" content="前端部分-how2j">
<meta property="og:url" content="https://wrr123.github.io/2021/03/12/%E5%89%8D%E7%AB%AF%E9%83%A8%E5%88%86-how2j/index.html">
<meta property="og:site_name" content="一缕烟气">
<meta property="og:description" content="HTML中文问题可以在浏览器上设置编码方式为GB2312，或者在html的最前面加上编码 123&lt;html&gt;    &lt;meta http-equiv&#x3D;&quot;Content-Type&quot; content&#x3D;&quot;text&#x2F;html;charset&#x3D;GB2312&quot;&#x2F;&gt;&lt;&#x2F;html&gt; 元素 完整的HTML 一个完整的html文件应该至少包含html元素，body元素，以及里面的内">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-12T05:32:44.000Z">
<meta property="article:modified_time" content="2022-02-18T02:52:04.534Z">
<meta property="article:author" content="田园隐士">
<meta property="article:tag" content="how2j">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://wrr123.github.io/2021/03/12/%E5%89%8D%E7%AB%AF%E9%83%A8%E5%88%86-how2j/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>前端部分-how2j | 一缕烟气</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<style>mjx-container[jax="SVG"] {
  direction: ltr;
}

mjx-container[jax="SVG"] > svg {
  overflow: visible;
}

mjx-container[jax="SVG"][display="true"] {
  display: block;
  text-align: center;
  margin: 1em 0;
}

mjx-container[jax="SVG"][justify="left"] {
  text-align: left;
}

mjx-container[jax="SVG"][justify="right"] {
  text-align: right;
}

g[data-mml-node="merror"] > g {
  fill: red;
  stroke: red;
}

g[data-mml-node="merror"] > rect[data-background] {
  fill: yellow;
  stroke: none;
}

g[data-mml-node="mtable"] > line[data-line] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > rect[data-frame] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > .mjx-dashed {
  stroke-dasharray: 140;
}

g[data-mml-node="mtable"] > .mjx-dotted {
  stroke-linecap: round;
  stroke-dasharray: 0,140;
}

g[data-mml-node="mtable"] > svg {
  overflow: visible;
}

[jax="SVG"] mjx-tool {
  display: inline-block;
  position: relative;
  width: 0;
  height: 0;
}

[jax="SVG"] mjx-tool > mjx-tip {
  position: absolute;
  top: 0;
  left: 0;
}

mjx-tool > mjx-tip {
  display: inline-block;
  padding: .2em;
  border: 1px solid #888;
  font-size: 70%;
  background-color: #F8F8F8;
  color: black;
  box-shadow: 2px 2px 5px #AAAAAA;
}

g[data-mml-node="maction"][data-toggle] {
  cursor: pointer;
}

mjx-status {
  display: block;
  position: fixed;
  left: 1em;
  bottom: 1em;
  min-width: 25%;
  padding: .2em .4em;
  border: 1px solid #888;
  font-size: 90%;
  background-color: #F8F8F8;
  color: black;
}

foreignObject[data-mjx-xml] {
  font-family: initial;
  line-height: normal;
  overflow: visible;
}

.MathJax path {
  stroke-width: 3;
}

mjx-container[display="true"] {
  overflow: auto hidden;
}

mjx-container[display="true"] + br {
  display: none;
}
</style><link rel="alternate" href="/atom.xml" title="一缕烟气" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一缕烟气</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">沧海月明珠有泪，蓝田日暖玉生烟</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/03/12/%E5%89%8D%E7%AB%AF%E9%83%A8%E5%88%86-how2j/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          前端部分-how2j
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-12 13:32:44" itemprop="dateCreated datePublished" datetime="2021-03-12T13:32:44+08:00">2021-03-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h4 id="HTML"><a href="#HTML" class="headerlink" title="HTML"></a>HTML</h4><h5 id="中文问题"><a href="#中文问题" class="headerlink" title="中文问题"></a>中文问题</h5><p>可以在浏览器上设置编码方式为<code>GB2312</code>，或者在html的最前面加上编码</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Content-Type"</span> <span class="attr">content</span>=<span class="string">"text/html;charset=GB2312"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h5 id="元素"><a href="#元素" class="headerlink" title="元素"></a>元素</h5><ul>
<li><p>完整的HTML</p>
<p>一个完整的html文件应该至少包含html元素，body元素，以及里面的内容。</p>
</li>
<li><p>不完整的元素</p>
</li>
<li><p>有的特殊元素</p>
<p>有的特殊元素，没有内容，即开始和结束标签直接放在一起。</p>
<p>比如hr, br等等。</p>
</li>
</ul>
<h6 id="属性"><a href="#属性" class="headerlink" title="属性"></a>属性</h6><p>属性是用来修饰标签的。</p>
<h6 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h6><p>html用<code>&lt;!-- --&gt;</code>来进行注释。</p>
<h5 id="基本元素"><a href="#基本元素" class="headerlink" title="基本元素"></a>基本元素</h5><div class="table-container">
<table>
<thead>
<tr>
<th>格式</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;h1&gt; 到 &lt;h6&gt;</code></td>
<td>分别表示不同大小的标题</td>
</tr>
<tr>
<td><code>&lt;p&gt;</code></td>
<td>段落，自带换行</td>
</tr>
<tr>
<td><code>&lt;b&gt; 或 &lt;strong&gt;</code></td>
<td>粗体</td>
</tr>
<tr>
<td><code>&lt;i&gt; 或 &lt;em&gt;</code></td>
<td>斜体</td>
</tr>
<tr>
<td><code>&lt;pre&gt;</code></td>
<td>在网页上显示代码，如java代码等</td>
</tr>
<tr>
<td><code>&lt;del&gt;</code></td>
<td>删除线效果</td>
</tr>
<tr>
<td><code>&lt;ins&gt;</code></td>
<td>下划线，其中<u>标签也可以实现下划线效果，但是不建议使用</u></td>
</tr>
<tr>
<td><code>&lt;img&gt;</code></td>
<td>图像</td>
</tr>
<tr>
<td><code>&lt;a&gt;</code></td>
<td>超链接</td>
</tr>
<tr>
<td><code>&lt;table&gt;，&lt;tr&gt;, &lt;td&gt;</code></td>
<td>表格, 行， 单元格</td>
</tr>
<tr>
<td><code>&lt;ul&gt;, &lt;ol&gt;</code></td>
<td>无序列表， 有序列表</td>
</tr>
<tr>
<td><code>&lt;div&gt;, &lt;span&gt;</code></td>
<td>块级元素， 内联元素，它们通常结合CSS来进行页面布局</td>
</tr>
</tbody>
</table>
</div>
<h5 id="字体"><a href="#字体" class="headerlink" title="字体"></a>字体</h5><h6 id="字体元素"><a href="#字体元素" class="headerlink" title="字体元素"></a>字体元素</h6><p>font常用的属性有color和size，分别表示颜色和大小。</p>
<h6 id="颜色表示法"><a href="#颜色表示法" class="headerlink" title="颜色表示法"></a>颜色表示法</h6><ul>
<li>颜色名，如<code>red, blue</code></li>
<li>颜色对应的16进制，如<code>#ff0000</code>就表示红色。</li>
</ul>
<h5 id="内联框架"><a href="#内联框架" class="headerlink" title="内联框架"></a>内联框架</h5><p><code>&lt;iframe&gt;</code>即内联框架，通过内联框架可以实现在网页中<code>插入</code>网页。</p>
<h6 id="表单元素"><a href="#表单元素" class="headerlink" title="表单元素"></a>表单元素</h6><div class="table-container">
<table>
<thead>
<tr>
<th>格式</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&lt;input type="text"&gt;</code></td>
<td>文本框</td>
</tr>
<tr>
<td><code>&lt;input type="password"&gt;</code></td>
<td>密码框</td>
</tr>
<tr>
<td><code>&lt;form&gt;</code></td>
<td>表单</td>
</tr>
<tr>
<td><code>&lt;input type="radio"&gt;</code></td>
<td>单选框</td>
</tr>
<tr>
<td><code>&lt;input type="checked"&gt;</code></td>
<td>复选框</td>
</tr>
<tr>
<td><code>&lt;select&gt; &lt;option&gt;</code></td>
<td>下拉列表</td>
</tr>
<tr>
<td><code>&lt;textarea&gt;</code></td>
<td>文本域</td>
</tr>
<tr>
<td><code>&lt;input type="button"&gt;</code></td>
<td>普通按钮</td>
</tr>
<tr>
<td><code>&lt;input type="submit"&gt;</code></td>
<td>提交按钮</td>
</tr>
<tr>
<td><code>&lt;input type="reset"&gt;</code></td>
<td>重置按钮</td>
</tr>
<tr>
<td><code>&lt;input type="image"&gt;</code></td>
<td>使用图像作为按钮进行form的提交</td>
</tr>
<tr>
<td><code>&lt;button&gt;</code></td>
<td>按钮标签</td>
</tr>
</tbody>
</table>
</div>
<h4 id="CSS"><a href="#CSS" class="headerlink" title="CSS"></a>CSS</h4><h5 id="css语法"><a href="#css语法" class="headerlink" title="css语法"></a>css语法</h5><p><code>selector {property: value}</code>,即</p>
<p>选择器 {属性: 值}。</p>
<h5 id="css选择器"><a href="#css选择器" class="headerlink" title="css选择器"></a>css选择器</h5><ul>
<li><p>元素选择器</p>
</li>
<li><p>id选择器</p>
</li>
<li><p>类选择器</p>
</li>
<li><p>更准确的选择(同时根据元素名和class来选择)</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">p</span><span class="selector-class">.blue</span>{</span><br><span class="line">  <span class="attribute">color</span>:blue;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h5 id="注释-1"><a href="#注释-1" class="headerlink" title="注释"></a>注释</h5><p>以<code>/*</code> 开始，以<code>*/</code>结束。</p>
<h5 id="常用的CSS属性"><a href="#常用的CSS属性" class="headerlink" title="常用的CSS属性"></a>常用的CSS属性</h5><div class="table-container">
<table>
<thead>
<tr>
<th>属性</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>width, height</td>
<td>尺寸大小，元素的宽度和高度</td>
</tr>
<tr>
<td>background-*（color，image）</td>
<td>背景（颜色，图片）</td>
</tr>
<tr>
<td>color</td>
<td>文字颜色</td>
</tr>
<tr>
<td>text-align</td>
<td>对齐</td>
</tr>
<tr>
<td>text-decoration</td>
<td>文本修饰</td>
</tr>
<tr>
<td>line-height</td>
<td>行间距</td>
</tr>
<tr>
<td>letter-spacing</td>
<td>字符间距</td>
</tr>
<tr>
<td>word-spacing</td>
<td>单词间距</td>
</tr>
<tr>
<td>text-index</td>
<td>首行缩进</td>
</tr>
<tr>
<td>text-transform</td>
<td>大小写</td>
</tr>
<tr>
<td>white-space</td>
<td>空白格</td>
</tr>
<tr>
<td>font-size</td>
<td>尺寸</td>
</tr>
<tr>
<td>font-style</td>
<td>风格</td>
</tr>
<tr>
<td>font-weight</td>
<td>粗细</td>
</tr>
<tr>
<td>font-family</td>
<td>字库</td>
</tr>
<tr>
<td>cursor</td>
<td>鼠标样式</td>
</tr>
<tr>
<td>table-layout</td>
<td>表格布局</td>
</tr>
<tr>
<td>border-collapse</td>
<td>表格边框</td>
</tr>
<tr>
<td>border-style</td>
<td>边框风格</td>
</tr>
<tr>
<td>border-color</td>
<td>边框颜色</td>
</tr>
<tr>
<td>border-width</td>
<td>边框宽度</td>
</tr>
<tr>
<td>padding</td>
<td>内边距，指元素的内容和边框之间的距离</td>
</tr>
<tr>
<td>margin</td>
<td>外边距，指元素边框和元素边框之间的距离</td>
</tr>
</tbody>
</table>
</div>
<h5 id="css优先级问题"><a href="#css优先级问题" class="headerlink" title="css优先级问题"></a>css优先级问题</h5><ol>
<li><code>!important</code></li>
<li>style属性</li>
<li>style标签</li>
<li>外部css文件</li>
</ol>
<h5 id="布局"><a href="#布局" class="headerlink" title="布局"></a>布局</h5><ul>
<li><p>绝对定位 <code>position: absolute;</code></p>
</li>
<li><p>相对定位 <code>position: relative;</code></p>
</li>
<li><p>浮动 <code>float:left/right;</code></p>
<p>清楚浮动带来的影响，使用 <code>clear</code>.</p>
</li>
</ul>
<h4 id="JavaScript"><a href="#JavaScript" class="headerlink" title="JavaScript"></a>JavaScript</h4><h5 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h5><p>JavaScript用于网页与用户之间的交互，完整的JavaScript由语言基础、BOM和DOM组成。</p>
<h5 id="script标签"><a href="#script标签" class="headerlink" title="script标签"></a>script标签</h5><p>JavaScript代码必须放在script标签中，script标签可以放在html的任何地方，一般建议放在head标签里。</p>
<h5 id="调试方法"><a href="#调试方法" class="headerlink" title="调试方法"></a>调试方法</h5><ul>
<li>alert调试</li>
<li>使用浏览器自带的调试功能</li>
<li>console.log()调试</li>
</ul>
<h5 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h5><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>undefined</td>
<td>声明了但未赋值</td>
</tr>
<tr>
<td>Boolean</td>
<td>布尔</td>
</tr>
<tr>
<td>Number</td>
<td>数字</td>
</tr>
<tr>
<td>String</td>
<td>字符串</td>
</tr>
<tr>
<td>var</td>
<td>动态类型</td>
</tr>
<tr>
<td>typeof</td>
<td>变量类型判断</td>
</tr>
<tr>
<td>null</td>
<td>空对象、或对象不存在</td>
</tr>
</tbody>
</table>
</div>
<h5 id="作用域"><a href="#作用域" class="headerlink" title="作用域"></a>作用域</h5><ul>
<li>全局变量</li>
<li>局部变量</li>
</ul>
<h5 id="事件"><a href="#事件" class="headerlink" title="事件"></a>事件</h5><p>事件有很多种，比如鼠标移动、鼠标点击和键盘点击等等。</p>
<h5 id="错误处理"><a href="#错误处理" class="headerlink" title="错误处理"></a>错误处理</h5><p>JavaScript提供了一种try catch的错误处理机制，当有错误抛出的时候，可以catch住。</p>
<h5 id="对象"><a href="#对象" class="headerlink" title="对象"></a>对象</h5><ul>
<li>数字 Number</li>
<li>字符串 String</li>
<li>数组 Array</li>
<li>日期 Date</li>
<li>Math</li>
<li>自定义对象</li>
</ul>
<h5 id="BOM"><a href="#BOM" class="headerlink" title="BOM"></a>BOM</h5><p>浏览器对象模型（Browser Object Model）</p>
<ul>
<li>Window 窗口</li>
<li>Navigator 浏览器</li>
<li>Screen 客户端屏幕</li>
<li>History 访问历史</li>
<li>Location 浏览器地址</li>
</ul>
<h6 id="定时器"><a href="#定时器" class="headerlink" title="定时器"></a>定时器</h6><div class="table-container">
<table>
<thead>
<tr>
<th>关键字</th>
<th>简介</th>
</tr>
</thead>
<tbody>
<tr>
<td>setTimeout</td>
<td>只执行一次</td>
</tr>
<tr>
<td>setInterval</td>
<td>不停的重复执行</td>
</tr>
<tr>
<td>clearInterval</td>
<td>终止重复执行</td>
</tr>
</tbody>
</table>
</div>
<p><strong>不要在setInterval调用的函数中使用<code>document.write();</code></strong></p>
<h4 id="JSON"><a href="#JSON" class="headerlink" title="JSON"></a>JSON</h4><p>JSON JavaScript对象表示法（Java Script Object Notation）是一种存储数据的方式。</p>
<h5 id="对象转换"><a href="#对象转换" class="headerlink" title="对象转换"></a>对象转换</h5><ul>
<li><p>将字符串转换为JSON对象</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">var</span> s1 = <span class="string">"{\"name\":\"盖伦\""</span>;</span><br><span class="line"><span class="keyword">var</span> s2 = <span class="string">",\"hp\":616}"</span>;</span><br><span class="line"><span class="keyword">var</span> s3 = s1+s2;</span><br><span class="line"> </span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个JSON格式的字符串:"</span> + s3);</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"&lt;br&gt;"</span>);</span><br><span class="line"><span class="keyword">var</span> gareen = <span class="built_in">eval</span>(<span class="string">"("</span>+s3+<span class="string">")"</span>);</span><br><span class="line"> </span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个JSON对象: "</span> + gareen);</span><br><span class="line">  </span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>JSON对象转换为字符串</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">var</span> hero = {<span class="string">"name"</span>:<span class="string">"盖伦"</span>,<span class="string">"hp"</span>:<span class="string">"616"</span>};</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个json 对象："</span>+ hero);</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"&lt;br&gt;"</span>);</span><br><span class="line"><span class="keyword">var</span> heroString = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(hero)</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">"这是一个json 字符串："</span>+ heroString );</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/how2j/" rel="tag"># how2j</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/03/11/java%E4%B8%AD%E7%BA%A7-how2j/" rel="prev" title="java中级-how2j">
      <i class="fa fa-chevron-left"></i> java中级-how2j
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/03/13/JQuery-how2j/" rel="next" title="JQuery-how2j">
      JQuery-how2j <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#HTML"><span class="nav-number">1.</span> <span class="nav-text">HTML</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%B8%AD%E6%96%87%E9%97%AE%E9%A2%98"><span class="nav-number">1.1.</span> <span class="nav-text">中文问题</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%85%83%E7%B4%A0"><span class="nav-number">1.2.</span> <span class="nav-text">元素</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E5%B1%9E%E6%80%A7"><span class="nav-number">1.2.1.</span> <span class="nav-text">属性</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E6%B3%A8%E9%87%8A"><span class="nav-number">1.2.2.</span> <span class="nav-text">注释</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%9F%BA%E6%9C%AC%E5%85%83%E7%B4%A0"><span class="nav-number">1.3.</span> <span class="nav-text">基本元素</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AD%97%E4%BD%93"><span class="nav-number">1.4.</span> <span class="nav-text">字体</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E5%AD%97%E4%BD%93%E5%85%83%E7%B4%A0"><span class="nav-number">1.4.1.</span> <span class="nav-text">字体元素</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E9%A2%9C%E8%89%B2%E8%A1%A8%E7%A4%BA%E6%B3%95"><span class="nav-number">1.4.2.</span> <span class="nav-text">颜色表示法</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%86%85%E8%81%94%E6%A1%86%E6%9E%B6"><span class="nav-number">1.5.</span> <span class="nav-text">内联框架</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E8%A1%A8%E5%8D%95%E5%85%83%E7%B4%A0"><span class="nav-number">1.5.1.</span> <span class="nav-text">表单元素</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#CSS"><span class="nav-number">2.</span> <span class="nav-text">CSS</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#css%E8%AF%AD%E6%B3%95"><span class="nav-number">2.1.</span> <span class="nav-text">css语法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#css%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">2.2.</span> <span class="nav-text">css选择器</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%B3%A8%E9%87%8A-1"><span class="nav-number">2.3.</span> <span class="nav-text">注释</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84CSS%E5%B1%9E%E6%80%A7"><span class="nav-number">2.4.</span> <span class="nav-text">常用的CSS属性</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#css%E4%BC%98%E5%85%88%E7%BA%A7%E9%97%AE%E9%A2%98"><span class="nav-number">2.5.</span> <span class="nav-text">css优先级问题</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%B8%83%E5%B1%80"><span class="nav-number">2.6.</span> <span class="nav-text">布局</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JavaScript"><span class="nav-number">3.</span> <span class="nav-text">JavaScript</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AE%9A%E4%B9%89"><span class="nav-number">3.1.</span> <span class="nav-text">定义</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#script%E6%A0%87%E7%AD%BE"><span class="nav-number">3.2.</span> <span class="nav-text">script标签</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E8%B0%83%E8%AF%95%E6%96%B9%E6%B3%95"><span class="nav-number">3.3.</span> <span class="nav-text">调试方法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.4.</span> <span class="nav-text">基本数据类型</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="nav-number">3.5.</span> <span class="nav-text">作用域</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BA%8B%E4%BB%B6"><span class="nav-number">3.6.</span> <span class="nav-text">事件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86"><span class="nav-number">3.7.</span> <span class="nav-text">错误处理</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AF%B9%E8%B1%A1"><span class="nav-number">3.8.</span> <span class="nav-text">对象</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#BOM"><span class="nav-number">3.9.</span> <span class="nav-text">BOM</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E5%AE%9A%E6%97%B6%E5%99%A8"><span class="nav-number">3.9.1.</span> <span class="nav-text">定时器</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JSON"><span class="nav-number">4.</span> <span class="nav-text">JSON</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AF%B9%E8%B1%A1%E8%BD%AC%E6%8D%A2"><span class="nav-number">4.1.</span> <span class="nav-text">对象转换</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">田园隐士</p>
  <div class="site-description" itemprop="description">talk is cheap, show me the code</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">347</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">53</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">田园隐士</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">587k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">8:53</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
          load: ['[tex]/mhchem'],
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
          packages: {'[+]': ['mhchem']},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

</body>
</html>
